package com.company.dcm.job.cycle;

import lombok.extern.slf4j.Slf4j;
import org.apache.tomcat.util.http.fileupload.FileUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

/**
 *
 */
@Component
@Slf4j
public class CleanPictures {
    private static final String filePath = "/usr/share/nginx/html/image/baiduSyncdisk/changfeng505/xiaci";
    /**
     * 每天执行一次
     */
    @Scheduled(cron =  "0 0 2 * * ?")
    public void run() {
        // 获取当前日期
        String currentDate = LocalDate.now().minus(30, ChronoUnit.DAYS).toString();
        String fileName = filePath + "/" + currentDate;

        File file = new File(fileName);
        try {
            FileUtils.deleteDirectory(file);
        } catch (IOException e) {
            System.out.println("Failed to delete file " + file);
        }
    }

}
